/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package classesDAO;

import classes.Usuario;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author andre
 */
public class DAOUsuario {

    private Connection con;
    /*
     * poderia ter passado apenas login e senha
     */

    public Usuario verificaLogin(Usuario us) {
        Usuario usuario = new Usuario();//retorno
        try {
            con = (Connection) Conexao.getConnection();
            PreparedStatement ps = (PreparedStatement)
            con.prepareStatement("select  id, nome,login,senha "+
             "from usuario where login= ? and senha= ?");
            ps.setString(1, us.getLogin());
            ps.setString(2, us.getSenha());
            ResultSet rs = ps.executeQuery();
            rs.next();
            usuario.setId(rs.getInt("id")); 
            usuario.setNome(rs.getString("nome"));
            usuario.setLogin(rs.getString("login"));
            usuario.setSenha(rs.getString("senha"));
            rs.close();
            ps.close();
            con.close();

        } catch (SQLException ex) {
            System.out.println(ex.getMessage().toString());
        }
        return usuario;
    }
}
